package com.tobe.spring_demo.lifecycle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Component;

/**
 * @author yangqifan 2015年9月16日
 * 
 */
@Component
public class LFOne implements SmartLifecycle {
	
	@Autowired
	private LFTwo two;//循环引用,这里不影响对象创建
	
	public void setTwo(LFTwo two) {
		this.two = two;
	}
	
	boolean running;

	public void start() {
		
		System.out.println("LFOne run start...");
		running = true;
	}

	public void stop() {
		//如果是实现的smartLifecycle是调用stop(callback)不会调用这里
		System.out.println("LFOne run stop...");
	}

	public boolean isRunning() {
		return running;
	}

	public int getPhase() {
		return 2;
	}

	public boolean isAutoStartup() {
		return true;
	}

	public void stop(Runnable callback) {
		System.out.println(two);
		System.out.println("LFOne run stop callback...");
	}

}

